package com.ai.aicodemather.core.saver;

import com.ai.aicodemather.ai.model.MultiFileCodeResult;
import com.ai.aicodemather.exception.ErrorCode;
import com.ai.aicodemather.exception.ThrowUtils;
import com.ai.aicodemather.model.enums.CodeGenTypeEnum;

/**
 * HTML代码文件保存模板
 */
public class MutiFileCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult> {

    /**
     * 获取代码生成类型
     *
     * @return
     */
    @Override
    protected CodeGenTypeEnum getCodeGenType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    /**
     * 保存代码文件
     *
     * @param filePath
     * @param result
     */
    @Override
    protected void saveFiles(String filePath, MultiFileCodeResult result) {
        saveSingleFile(filePath, "index.html", result.getHtmlCode());
        saveSingleFile(filePath, "style.css", result.getCssCode());
        saveSingleFile(filePath, "script.js", result.getJsCode());
    }

    @Override
    protected void validateInput(MultiFileCodeResult result) {
        super.validateInput(result);
        ThrowUtils.throwIf(result.getHtmlCode() == null, ErrorCode.PARAMS_ERROR, "HTML代码不能为空");
    }
}
